import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    redirect: '/home',  // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'find',
        name: 'Find',
        component: () => import(/* webpackChunkName: "about" */ '../views/Home/Find.vue'),
        meta: {
          title: "找房",
          icon: "point-gift-o"
        }
      },
      {
        path: 'home',
        name: 'Home',
        component: () => import(/* webpackChunkName: "about" */ '../views/Home/Home.vue'),
        meta: {
          title: "首页",
          icon: "point-gift-o"
        }
      },
      {
        path: 'message',
        name: 'Message',
        component: () => import(/* webpackChunkName: "about" */ '../views/Home/Message.vue'),
        meta: {
          title: "信息",
          icon: "point-gift-o"
        }
      },
      {
        path: 'my',
        name: 'My',
        component: () => import(/* webpackChunkName: "about" */ '../views/Home/My.vue'),
        meta: {
          title: "我的",
          icon: "point-gift-o"
        }
      },
      {
        path: 'send',
        name: 'Send',
        component: () => import(/* webpackChunkName: "about" */ '../views/Home/Send.vue'),
        meta: {
          title: "发布",
          icon: "point-gift-o"
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
  {
    path: '*',
    name: 'Notfound',
    component: () => import(/* webpackChunkName: "about" */ '../views/Notfound.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

router.beforeEach((to, from, next) => {
  console.log(to);
  document.title = to.meta.title;
  if (to.name == "My") 
  {
    console.log("要到我的页面了")
    const isLogin = localStorage.getItem('isLogin')
    if (isLogin == "true") {
      console.log("你已经登录了")
    }
    else {
      console.log("你还未登录");
      next("/login")
    }
  }
  next();
})
